package cn.dai.config;

import cn.dai.advice.AuthHandlerInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @author daijiyong
 */
@Configuration
public class AuthWebMvcConfigurer implements WebMvcConfigurer {
    @Resource
    AuthHandlerInterceptor authHandlerInterceptor;

    private final String[] excludePathPatters = new String[]{"/api/wechat/token/getToken", "/api/test/**"};

    /**
     * 给除了 excludePathPatters 配置的接口都配置拦截器,拦截转向到 authHandlerInterceptor
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authHandlerInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(excludePathPatters);
    }
}
